<?php  //UTF-8
  if($step != 3)
    die();
    
  include_once('./includes/funcs_wow.php');
?>

<!-- STYLES -->
  <style type="text/css">
    .form table {
      /*width: 100%;*/
      margin: 10px auto 10px auto;
      border-spacing: 8px 0px;
    }
    
    table tr td {
      text-align: left;
    }
  </style>

<!-- SCRIPTS -->
    <script type="text/javascript">
    <!--
      /*function set_form(typ) {
        if(typ == 0) {
          document.getElementById('spec_form').innerHTML = 'Simple Text options: <tr><td>Character full name:</td><td><input type="text" name="field1"></td></tr>';
        } else {
          document.getElementById('spec_form').innerHTML = 'My Character options: <tr><td>Character name:</td><td><input type="text" name="field1"></td></tr>';
        }
      }*/
      
      function setPreviewColor(field, val) {
        document.getElementById('f'+field+'_c_prev').style.background = '#'+val;
      }
      
      function setHexColor(field, val) {
        document.getElementById('f'+field+'_c').value = val;
      }
      
      function showShadowOpts(field, val) {
        if(val) {
          document.getElementById('f'+field+'_sh_opts').style.display = 'table-cell';
        } else {
          document.getElementById('f'+field+'_sh_opts').style.display = 'none';
        }
      }
      
      function setPreviewColorShadow(field, val) {
        document.getElementById('f'+field+'_c_prev_sh').style.background = '#'+val;
      }
      
      function setHexColorShadow(field, val) {
        document.getElementById('f'+field+'_c_sh').value = val;
      }
      
      function refresh_prev() {
        var param  = [];
        var string = '<?php echo intval($_POST['background']); ?>|<?php echo intval($_POST['num_texts']); ?>|<?php echo time(); ?>';
        
        for(i=1; i<=<?php echo intval($_POST['num_texts']); ?>; i++) {
          param[0] = document.getElementById('f'+i+'_v').value;
          param[1] = document.getElementById('f'+i+'_f').value;
          param[2] = document.getElementById('f'+i+'_c').value;
          param[3] = document.getElementById('f'+i+'_sh').checked;
          param[4] = document.getElementById('f'+i+'_c_sh').value;
          param[5] = document.getElementById('f'+i+'_sh_x').value;
          param[6] = document.getElementById('f'+i+'_sh_y').value;
          string = string+'||'+param[0]+'|'+param[1]+'|'+param[2]+'|'+param[3]+'|'+param[4]+'|'+param[5]+'|'+param[6];
        }
        
        document.getElementById('prev_img').src = './includes/live_preview.php?data='+escape(string);
      }
      
      window.onload = refresh_prev;
    -->
    </script>
    
<!-- BODY -->
        <?php 
        
          function get_ColList($id, $sh=false) {
            if ($sh) $shtxt = 'Shadow'; else $shtxt = '';
            return ('
            <select onchange="setHexColor'.$shtxt.'('.$id.', this.value); setPreviewColor'.$shtxt.'('.$id.', this.value);">
              <option value="">---</option>
              <option value="000000">Black</option>
              <option value="808080">Gray</option>
              <option value="C0C0C0">Silver</option>
              <option value="FFFFFF">White</option>
              <option value="0000FF">Blue</option>
              <option value="FF0000">Red</option>
              <option value="008000">Green</option>
              <option value="800000">Maroon</option>
              <option value="800080">Purple</option>
              <option value="FF00FF">Fuchsia</option>
              <option value="00FF00">Lime</option>
              <option value="808000">Olive</option>
              <option value="FFFF00">Yellow</option>
              <option value="000080">Navy</option>
              <option value="008080">Teal</option>
              <option value="00FFFF">Aqua</option>
            </select>
            ');
          }
          
          function get_FontList($id, $default=0) {
            $x = 0;
            $sql_return = @mysql_query('SELECT `id`,`name` FROM `'.TAB_SRC.'` WHERE `type`="FONT"');
            while($sql_data = @mysql_fetch_assoc($sql_return)) {
              $all_font[$x] = $sql_data;
              $x++;
            }
            $output = '';

            $output .= '
            <select name="f'.$id.'_font" id="f'.$id.'_f">
            ';
              for($i=0; $i<count($all_font); $i++) {
                if($all_font[$i]['id'] == $default)
                  $output .= '  <option selected="selected" value="'.$all_font[$i]['id'].'">'.$all_font[$i]['name'].'</option>
            ';
                else
                  $output .= '  <option value="'.$all_font[$i]['id'].'">'.$all_font[$i]['name'].'</option>
            ';
              }
            $output .= '
            </select>
            ';
            
            return $output;
          }
          
          
          $sql_return = @mysql_query('SELECT * FROM `'.TAB_SRC.'` WHERE `id`='.intval($_POST['background']).' AND `type`="SIGNATURE" LIMIT 1');
          $sql_data = @mysql_fetch_assoc($sql_return);
          if($sql_data['id'] == null) die('Error Siganture ID.');
          
          if($_POST['num_texts'] > $sql_data['fields']) {
            $data_count = $sql_data['fields'];
          } elseif($_POST['num_texts'] < 1) {
            $data_count = 1;
          } else {
            $data_count = intval($_POST['num_texts']);
          }
          
          if($_POST['sign_type'] == 0) {
            for($i=1; $i<=$data_count; $i++) {
              $form[$i] = strtr($_POST['value_'.$i], '|"\'', '   ');
            }
          } elseif($_POST['sign_type'] == 1) {
            $form[1] = strtr($_POST['value_1'], '|"\'', '   ');
            for($i=2; $i<=$data_count; $i++) {
              if($_POST['func_'.$i] == 0)
                $form[$i] = strtr($_POST['value_'.$i], '|"\'', '   ');
              else {
                $form[$i] = SELECT(PATCH, addslashes($form[1]), intval($_POST['func_'.$i]));
              }
            }
            if(get_usr_id(addslashes(strtr($_POST['value_1'], '|"\'', '   '))) === false)
              $warning = 'Your character does not exists.<br>Click "<= Back" and try type valid name';
          } else {
            $form[1] = SELECT(PATCH, addslashes(strtr($_POST['value_1'], '|"\'', '   ')), 0);
            for($i=2; $i<=$data_count; $i++) {
              if($_POST['func_'.$i] == 0)
                $form[$i] = $_POST['value_'.$i];
              else {
                $form[$i] = SELECT(PATCH, addslashes(strtr($_POST['value_1'], '|"\'', '   ')), intval($_POST['func_'.$i]));
              }
            }
            if(get_usr_id(addslashes(strtr($_POST['value_1'], '|"\'', '   '))) === false)
              $warning = 'Your character does not exists.<br>Click "<= Back" and try type valid name';
          }
        ?>
        
        <table>
          <tr>
            <td colspan="8" style="color:red; font-size: 18px; text-align: center;">
              <?php echo $warning; ?>
            </td>
          </tr>
          <tr>
            <td>
              Character name: 
            </td>
            <td>
              <input type="text" name="f1_value" value="<?php echo $form[1]; ?>" id="f1_v" maxlength="20" readonly="readonly">
            </td>
            <td style="padding-left: 20px;">
              Font: 
            </td>
            <td>
              <?php echo get_FontList(1, $sql_data['f1_f']); ?>
            </td>
            <td style="padding-left: 20px;">
              Color: 
            </td>
            <td>
              #<input type="text" name="f1_color" value="<?php echo $sql_data['f1_c'];?>" id="f1_c" maxlength="6" size="7" onchange="setPreviewColor(1, this.value);" onKeyUp="setPreviewColor(1, this.value);">
            </td>
            <td>
              <div id="f1_c_prev" style="margin-left: -9px; margin-right: 3px; width:20px; height: 20px; background-color: #<?php echo $sql_data['f1_c'];?>; vertical-align: middle; border: solid black 1px;"></div>
            </td>
            <td>
              <?php echo get_ColList(1, false); ?>
            </td>
          </tr>
          <tr>
            <td>
              <table>
                <tr>
                  <td>
                    <input type="checkbox" name="f1_shadow" id="f1_sh" style="margin-left: 8px;" checked="checked" onclick="showShadowOpts(1, this.checked);"> Shadow
                  </td>
                </tr>
              </table>
            </td>
            <td id="f1_sh_opts" colspan="7">
              <table>
                <tr>
                  <td>
                    Color: 
                  </td>
                  <td>
                    #<input type="text" name="f1_color_shadow" value="808080" id="f1_c_sh" maxlength="6" size="7" onchange="setPreviewColorShadow(1, this.value);" onKeyUp="setPreviewColorShadow(1, this.value);" s/tyle="float: left;">
                  </td>
                  <td>
                    <div id="f1_c_prev_sh" style="margin-left: -9px; margin-right: 3px; width:20px; height: 20px; background-color: #808080; vertical-align: middle; border: solid black 1px;"></div>
                  </td>
                  <td>
                    <?php echo get_ColList(1, true); ?>
                  </td>
                  
                  <td style="padding-left: 20px;">
                    Position: 
                  </td>
                  <td>
                    X: <input name="f1_sh_movex" id="f1_sh_x" type="text" size="2" maxlength="2" value="1">
                  </td>
                  <td>
                    Y: <input name="f1_sh_movey" id="f1_sh_y" type="text" size="2" maxlength="2" value="1">
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          
          <input type="hidden" id="sign_type"  name="sign_type"  value="<?php echo $_POST['sign_type']?>">
          <input type="hidden" id="background" name="background" value="<?php echo $_POST['background']?>">
          <input type="hidden" id="num_texts"  name="num_texts"  value="<?php echo $_POST['num_texts']?>">
          
        <?php
          for($i=1; $i<=$data_count; $i++) {
            if($_POST['sign_type'] == 0)
              echo('<input type="hidden" id="value_'.$i.'"  name="value_'.$i.'"  value="'.$_POST['value_'.$i].'">');
            else
              echo('<input type="hidden" id="func_'.$i.'"  name="func_'.$i.'"  value="'.$_POST['func_'.$i].'">  <input type="hidden" id="value_'.$i.'"  name="value_'.$i.'"  value="'.$_POST['value_'.$i].'">');
          }
        ?>
          
        <?php   
          for($i=2; $i<=$data_count; $i++) {
            echo('
              <tr>
                <td>
                  Text '.$i.': 
                </td>
                <td>
                  <input type="text" name="f'.$i.'_value" value="'.$form[$i].'" id="f'.$i.'_v" maxlength="20" readonly="readonly">
                </td>
                <td style="padding-left: 20px;">
                  Font: 
                </td>
                <td>
                  '.get_FontList($i, $sql_data['f'.$i.'_f']).'
                </td>
                <td style="padding-left: 20px;">
                  Color: 
                </td>
                <td>
                  #<input type="text" name="f'.$i.'_color" value="'.$sql_data['f'.$i.'_c'].'" id="f'.$i.'_c" maxlength="6" size="7" onchange="setPreviewColor('.$i.', this.value);" onKeyUp="setPreviewColor('.$i.', this.value);">
                </td>
                <td>
                  <div id="f'.$i.'_c_prev" style="margin-left: -9px; margin-right: 3px; width:20px; height: 20px; background-color: #'.$sql_data['f'.$i.'_c'].'; vertical-align: middle; border: solid black 1px;"></div>
                </td>
                <td>
                  '.get_ColList($i, false).'
                </td>
              </tr>
              <tr>
                <td>
                  <table>
                    <tr>
                      <td>
                        <input type="checkbox" name="f'.$i.'_shadow" id="f'.$i.'_sh" style="margin-left: 8px;" onclick="showShadowOpts('.$i.', this.checked);"> Shadow
                      </td>
                    </tr>
                  </table>
                </td>
                <td id="f'.$i.'_sh_opts" style="display: none;" colspan="7">
                  <table>
                    <tr>
                      <td>
                        Color: 
                      </td>
                      <td>
                        #<input type="text" name="f'.$i.'_color_shadow" value="808080" id="f'.$i.'_c_sh" maxlength="6" size="7" onchange="setPreviewColorShadow('.$i.', this.value);" onKeyUp="setPreviewColorShadow('.$i.', this.value);" s/tyle="float: left;">
                      </td>
                      <td>
                        <div id="f'.$i.'_c_prev_sh" style="margin-left: -9px; margin-right: 3px; width:20px; height: 20px; background-color: #808080; vertical-align: middle; border: solid black 1px;"></div>
                      </td>
                      <td>
                        '.get_ColList($i, true).'
                      </td>
                      
                      <td style="padding-left: 20px;">
                        Position: 
                      </td>
                      <td>
                        X: <input name="f'.$i.'_sh_movex" id="f'.$i.'_sh_x" type="text" size="2" maxlength="2" value="1">
                      </td>
                      <td>
                        Y: <input name="f'.$i.'_sh_movey" id="f'.$i.'_sh_y" type="text" size="2" maxlength="2" value="1">
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            ');
          }
        ?>
          
          <tr>
            <td colspan="8" style="padding-top: 20px; text-align: center;">
              <button type="button" onclick="refresh_prev();">Refresh Preview</button><br>
              <img id="prev_img" src=""> <!--./includes/get_preview.php?get=<?php echo $_POST['background']; ?>-->
            </td>
          </tr>
          
          <tr>
            <td colspan="8" style="padding-top: 20px; text-align: right;">
              <input type="submit" name="step3" value="Continue &#187;">
            </td>
          </tr>
          
        </table>